package com.toman.Util;


import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;
import com.toman.Adpter.ItemListAdapter;
import com.toman.Enum.NetworkEnum;
import com.toman.Interfaces.NewBaseUrl;
import com.toman.JavaBean.DeviceHouseDayPlanMappingEntity;
import com.toman.JavaBean.ProductEntity;
import com.toman.MyApplication;
import com.toman.R;
import com.toman.bean.DialogBean;
import com.toman.bean.ItemListBean;
import com.toman.bean.TemplateInfBean;
import com.toman.widget.ClearEditText;
import com.toman.widget.MyListView;
import com.zhy.adapter.recyclerview.CommonAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Request;
import okhttp3.Response;

import static com.toman.Util.DensityUtil.dip2px;


public class DialogUtils {

    private static final String TAG = "DialogUtils";

    /**
     * @param context
     * @param title   标题
     *                //     *@param items 编辑、删除
     *                //     *@param itemClickListener list_item_sign_list_more 对于的事件
     * @return
     * @Description: 显示 Edit 对话框(列表对话框形式 )
     * @Author:杨攀
     * @Since: 2015年6月23日上午9:37:36
     */
    public static AlertDialog.Builder createEditDialog(Context context, int title) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(title);// 标题
        return builder;
    }


    public static AlertDialog.Builder createEditDialog(Context context, View view) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setView(view);
        return builder;
    }

    /**
     * @param ctx
     * @param msg
     * @Description: 定义一个显示消息的对话框
     * @Author:杨攀
     * @Since: 2014年6月6日下午3:24:24
     */
    public static void showDialog(final Context ctx, String msg) {
        // 创建一个AlertDialog.Builder对象
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(ctx).setMessage(msg).setCancelable(false);
            builder.setTitle(R.string.app_dialog_title);
            builder.setPositiveButton(R.string.app_dialog_ok, null);
            builder.create().show();
        } catch (Exception e) {
            Log.i(TAG, "对话框所在界面不在栈顶！");
        }
    }

    /**
     * @param ctx
     * @param msg //     *@param goHome
     * @Description: 定义一个显示消息的对话框
     * @Author:杨攀
     * @Since: 2014年6月6日下午3:24:24
     */
    public static void showDialog(final Context ctx, int msg) {
        // 创建一个AlertDialog.Builder对象
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(ctx).setMessage(msg).setCancelable(false);
            builder.setTitle(R.string.app_dialog_title);
            builder.setPositiveButton(R.string.app_dialog_ok, null);
            builder.create().show();
        } catch (Exception e) {
            Log.i(TAG, "对话框所在界面不在栈顶！");
        }

    }

    /**
     * @param ctx
     * @param view
     * @Description: 定义一个显示指定组件的对话框
     * @Author:杨攀
     * @Since: 2014年6月6日下午3:24:01
     */
    public static void showDialog(Context ctx, View view) {
        try {
            new AlertDialog.Builder(ctx).setView(view).setCancelable(false).create().show();
        } catch (Exception e) {
            Log.i(TAG, "对话框所在界面不在栈顶！");
        }

    }

//    public static AlertDialog showLoadingDialog(Context ctx) {
//        try {
//            LayoutInflater factory = LayoutInflater.from(ctx);
//            View view=factory.inflate(R.layout.layout_loading,null);
//            AlertDialog dialog=      new AlertDialog.Builder(ctx).setView(view).setCancelable(false).create().show();
//            return dialog;
//        } catch (Exception e) {
//            Log.i(TAG, "对话框所在界面不在栈顶！");
//        }
//    }

    /**
     * @param activity
     * @param msg
     * @Description: 定义一个显示消息的对话框, 点击按钮后，关闭(finish)当前 Activity
     * @Author:杨攀
     * @Since: 2014年6月12日上午10:55:58
     */
    public static void showDialogViewFinish(final Activity activity, int msg) {
        // 创建一个AlertDialog.Builder对象
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity).setMessage(msg);
            builder.setTitle(R.string.app_dialog_title);
            builder.setPositiveButton(R.string.app_dialog_ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    activity.finish();
                }
            }).show();
        } catch (Exception e) {
            Log.i(TAG, "对话框所在界面不在栈顶！");
        }

    }

    /**
     * @param activity
     * @param msg
     * @param positiveButtonListener 确定按钮的事件
     * @param negativeButtonListener 取消按钮的事件
     * @Description: 显示对话框
     * @Author:杨攀
     * @Since: 2014年8月20日上午11:27:08
     */
    public static void showDialog(Activity activity, int msg, OnClickListener positiveButtonListener, OnClickListener negativeButtonListener) {
        // 创建一个AlertDialog.Builder对象
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity).setMessage(msg);
            builder.setTitle(R.string.app_dialog_title);
            builder.setPositiveButton(R.string.app_dialog_ok, positiveButtonListener);
            builder.setNegativeButton(R.string.app_dialog_cancel, negativeButtonListener);
            builder.setCancelable(false);
            builder.show();

        } catch (Exception e) {
            Log.i(TAG, "对话框所在界面不在栈顶！");
        }

    }

    /**
     * @param activity
     * @param msg
     * @param positiveButtonListener 确定按钮的事件
     * @Description: 显示对话框
     * @Author: 杨攀
     * @Since: 2014年8月15日下午1:31:44
     */
    public static void showDialog(Activity activity, int msg, OnClickListener positiveButtonListener) {
        // 创建一个AlertDialog.Builder对象
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity).setMessage(msg);
            builder.setTitle(R.string.app_dialog_title);
            builder.setPositiveButton(R.string.app_dialog_ok, positiveButtonListener);
            builder.setNegativeButton(R.string.app_dialog_cancel, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        } catch (Exception e) {
            Log.i(TAG, "对话框所在界面不在栈顶！");
        }

    }

    public static void showDialog(Activity activity, String pos, String negative, OnClickListener positiveButtonListener, OnClickListener negativeButtonListener) {
        // 创建一个AlertDialog.Builder对象
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity).setMessage(R.string.app_dialog_content);
            builder.setTitle(R.string.app_dialog_title);
            builder.setPositiveButton(pos, positiveButtonListener);
            builder.setNegativeButton(negative, negativeButtonListener);
            builder.setCancelable(true);
            builder.show();

        } catch (Exception e) {
            Log.i(TAG, "对话框所在界面不在栈顶！");
        }

    }

    public static void showDialog(Activity activity, String msg, OnClickListener positiveButtonListener) {
        // 创建一个AlertDialog.Builder对象
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity).setMessage(msg);
            builder.setTitle(R.string.app_dialog_title);
            builder.setPositiveButton(R.string.app_dialog_ok, positiveButtonListener);
            builder.setNegativeButton(R.string.app_dialog_cancel, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.show();
        } catch (Exception e) {
            Log.i(TAG, "对话框所在界面不在栈顶！");
        }

    }
    /**
     * @param activity
     * @param dialogTitle
     * @param editHint
     * @param editText
     * @param view
     * @Description: 输入文本框的 对话框
     * @Author:杨攀
     * @Since: 2015年7月10日上午10:19:41
     */
    public static void showEditDialog(Activity activity, int dialogTitle, int editHint, String editText, final TextView view) {

        final EditText eText = new EditText(activity);
        eText.setHint(editHint);
        eText.setText(editText);
        eText.setSelection(eText.length());

        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(dialogTitle);
        builder.setView(eText);
        builder.setPositiveButton(R.string.app_dialog_ok, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                view.setText(eText.getText().toString());
            }
        }).show();
    }

    /**
     * @param activity
     * @param dialogTitle
     * @param editHint
     * @param editText
     * @param view
     * @Description: 显示数字编辑对话框
     * @Author:邹苏启
     * @Since: 2015-8-18下午7:04:32
     */
    public static void showNumerEditDialog(Activity activity, int dialogTitle, int editHint, String editText, final TextView view) {

        final EditText eText = new EditText(activity);
        eText.setHint(editHint);
        eText.setInputType(InputType.TYPE_CLASS_NUMBER);
        eText.setText(editText);
        eText.setSelection(eText.length());

        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(dialogTitle);
        builder.setView(eText);
        builder.setPositiveButton(R.string.app_dialog_ok, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                view.setText(eText.getText().toString());
            }
        }).show();
    }

    public static void showDialog(Context context, String title, String url, String name, ActionCallback callback
    ) {
        String token = (String) SPUtils.get(context, "token", "");
        String mCompanyId = (String) SPUtils.get(context, "cpy_id", "");

        ItemListAdapter adapter = new ItemListAdapter(context);
        List<ItemListBean> list = new ArrayList<>();
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list_search, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        EditText etSearch = (EditText) textEntryView.findViewById(R.id.et_search);
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                BaseNetUtil.base(context, title, url, name, list, token, mCompanyId, adapter, s.toString().trim());

            }
        });
        lv.setAdapter(adapter);
        builder                //对话框的标题
                .setTitle("选择" + title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //获取用户输入的“用户名”，“密码”
                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
        BaseNetUtil.base(context, title, url, name, list, token, mCompanyId, adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean bean1 = adapter.getItem(i);
                callback.run(bean1, dialog);
            }
        });
    }

    //使用枚举简化操作
    public static void showDialog(Context context, NetworkEnum anEnum, String mCompanyId, ActionCallback callback
    ) {
        String token = (String) SPUtils.get(context, "token", "");
        ItemListAdapter adapter = new ItemListAdapter(context);
        List<ItemListBean> list = new ArrayList<>();
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list_search, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        EditText etSearch = (EditText) textEntryView.findViewById(R.id.et_search);
        TextView tv_nodata = (TextView) textEntryView.findViewById(R.id.tv_nodata);

        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                BaseNetUtil.base(context, anEnum, list,tv_nodata, token, mCompanyId, adapter, s.toString().trim());

            }
        });
        lv.setAdapter(adapter);
        builder                //对话框的标题
                .setTitle("选择" + anEnum.title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //获取用户输入的“用户名”，“密码”
                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
        BaseNetUtil.base(context, anEnum, list,tv_nodata, token, mCompanyId, adapter, etSearch.getText().toString());
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean bean1 = adapter.getItem(i);
                callback.run(bean1, dialog);
            }
        });
    }
    public static void showDialog(Context context, NetworkEnum anEnum, String mCompanyId, Map<String, String> map,ActionCallback callback
    ) {
        String token = (String) SPUtils.get(context, "token", "");
        ItemListAdapter adapter = new ItemListAdapter(context);
        List<ItemListBean> list = new ArrayList<>();
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list_search, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        EditText etSearch = (EditText) textEntryView.findViewById(R.id.et_search);
        TextView tv_nodata = (TextView) textEntryView.findViewById(R.id.tv_nodata);
    TemplateInfBean bean=new TemplateInfBean();
    bean.setMap(map);
    bean.setCompanyId(mCompanyId);bean.setNetwork(anEnum);
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {

                BaseNetUtil.base(bean, list,adapter,tv_nodata, s.toString().trim());

            }
        });
        lv.setAdapter(adapter);
        builder                //对话框的标题
                .setTitle("选择" + anEnum.title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //获取用户输入的“用户名”，“密码”
                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
    BaseNetUtil.base(bean, list,adapter,tv_nodata, etSearch.getText().toString().trim());
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean bean1 = adapter.getItem(i);
                callback.run(bean1, dialog);
            }
        });
    }

    public static void showDialog(Context context,TemplateInfBean bean,ActionCallback callback
    ) {
        String token = (String) SPUtils.get(MyApplication.getInstance(), "token", "");
        ItemListAdapter adapter = new ItemListAdapter(context);
        List<ItemListBean> list = new ArrayList<>();
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list_search, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        EditText etSearch = (EditText) textEntryView.findViewById(R.id.et_search);
        TextView tv_nodata = (TextView) textEntryView.findViewById(R.id.tv_nodata);
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                BaseNetUtil.base(bean, list,adapter,tv_nodata, s.toString().trim());

            }
        });
        lv.setAdapter(adapter);
        builder                //对话框的标题
                .setTitle("选择" + bean.getNetwork().title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //获取用户输入的“用户名”，“密码”
                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
        BaseNetUtil.base(bean, list,adapter,tv_nodata, etSearch.getText().toString().trim());
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean bean1 = adapter.getItem(i);
                callback.run(bean1, dialog);
            }
        });
    }

    public static void showDialog(Context context, NetworkEnum anEnum, String mCompanyId,String listName, ActionCallback callback
    ) {
        String token = (String) SPUtils.get(context, "token", "");
        ItemListAdapter adapter = new ItemListAdapter(context);
        List<ItemListBean> list = new ArrayList<>();
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list_search, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        EditText etSearch = (EditText) textEntryView.findViewById(R.id.et_search);
        etSearch.setVisibility(View.GONE);
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                BaseNetUtil.base(context, anEnum, list, token, mCompanyId,listName, adapter, s.toString().trim());

            }
        });
        lv.setAdapter(adapter);
        builder                //对话框的标题
                .setTitle("选择" + anEnum.title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //获取用户输入的“用户名”，“密码”
                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
        BaseNetUtil.base(context, anEnum, list, token, mCompanyId,listName, adapter, etSearch.getText().toString());
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean bean1 = adapter.getItem(i);
                callback.run(bean1, dialog);
            }
        });
    }
//


    public static void showMutiDialog(Context context, TemplateInfBean bean, ActionCallback callback
    ) {
        String token = (String) SPUtils.get(context, "token", "");
        ItemListAdapter adapter = new ItemListAdapter(context,2);
        List<ItemListBean> list = new ArrayList<>();
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list_search, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        TextView tv_noData = (TextView) textEntryView.findViewById(R.id.tv_nodata);
        lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
        for (int i = 0; i < list.size(); i++) {
            lv.setItemChecked(i, false);
        }

        EditText etSearch = (EditText) textEntryView.findViewById(R.id.et_search);
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                BaseNetUtil.base(context, bean.getNetwork(), list,tv_noData, token, bean.getCompanyId(), adapter, s.toString().trim(),bean.getMap());

            }
        });
        lv.setAdapter(adapter);
        builder                //对话框的标题
                .setTitle("选择" + bean.getNetwork().title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确定", new OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        SparseBooleanArray array;
                        array = lv.getCheckedItemPositions();
                        StringBuilder name = new StringBuilder();
                        StringBuilder id = new StringBuilder();

                        for (int i = 0; i < list.size(); i++) {
                            ItemListBean bean = adapter.getItem(i);

                            if (array.get(i)) {
                                if (name.length() <= 0) {
                                    name.append(bean.getName());
                                    id.append(bean.getID());

                                } else {
                                    name.append(",").append(bean.getName());
                                    id.append(",").append(bean.getID());
                                }

                            }
                        }
                        if (name.length() <= 0) {
                            ToastUtil.makeText(context, "至少选中一个"+bean.getNetwork().title);
                            return;
                        } else {
                                            ItemListBean bean1 =new ItemListBean(name.toString(),id.toString());

                            callback.run(bean1,new Dialog(context));
                        }
                    }
                })
//                对话框的“退出”单击事件
                .setNegativeButton("取消", new OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                })
                .setNeutralButton("全选", null)

//                 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
        dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i=0;i<list.size() ;i++) {
                    lv.setItemChecked(i, true);
                }
                adapter.refreshData(list);
            }
        });
        BaseNetUtil.base(context, bean.getNetwork(), list,tv_noData, token, bean.getCompanyId(), adapter, etSearch.getText().toString(),bean.getMap());
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                ItemListBean bean1 = adapter.getItem(i);
//                callback.run(bean1, dialog);
            }
        });
    }

    public static void showMutiDialog(Context context, String selected,TemplateInfBean bean, ActionCallback callback
    ) {
        String token = (String) SPUtils.get(context, "token", "");
        ItemListAdapter adapter = new ItemListAdapter(context,2);
        List<ItemListBean> list = new ArrayList<>();
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list_search, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        TextView tv_noData = (TextView) textEntryView.findViewById(R.id.tv_nodata);
        lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
        for (int i = 0; i < list.size(); i++) {
            lv.setItemChecked(i, false);
        }




        EditText etSearch = (EditText) textEntryView.findViewById(R.id.et_search);
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                BaseNetUtil.base(context, bean.getNetwork(), list,tv_noData, token, bean.getCompanyId(), adapter, s.toString().trim(),bean.getMap());

            }
        });
        lv.setAdapter(adapter);
        builder                //对话框的标题
                .setTitle("选择" + bean.getNetwork().title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确定", new OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        SparseBooleanArray array;
                        array = lv.getCheckedItemPositions();
                        StringBuilder name = new StringBuilder();
                        StringBuilder id = new StringBuilder();

                        for (int i = 0; i < list.size(); i++) {
                            ItemListBean bean = adapter.getItem(i);

                            if (array.get(i)) {
                                if (name.length() <= 0) {
                                    name.append(bean.getName());
                                    id.append(bean.getID());

                                } else {
                                    name.append(",").append(bean.getName());
                                    id.append(",").append(bean.getID());
                                }

                            }
                        }
                        if (name.length() <= 0) {
                            ToastUtil.makeText(context, "至少选中一个"+bean.getNetwork().title);
                            return;
                        } else {
                            ItemListBean bean1 =new ItemListBean(name.toString(),id.toString());

                            callback.run(bean1,new Dialog(context));
                        }
                    }
                })
//                对话框的“退出”单击事件
                .setNegativeButton("取消", new OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                })
                .setNeutralButton("全选", null)

//                 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
        dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i=0;i<list.size() ;i++) {
                    lv.setItemChecked(i, true);
                }
                adapter.refreshData(list);
            }
        });
        BaseNetUtil.base(context, bean.getNetwork(), list,tv_noData, token, bean.getCompanyId(), adapter, etSearch.getText().toString(),bean.getMap(),new DefaultAcitonCallback() {
            @Override
            public void run( ) {
                if (StringUtils.isNotEmpty(selected)){
                    String []content=selected.split(",");
                    for (int i = 0; i < content.length; i++) {
                        for (int j=0;j<list.size();j++){
                            if (content[i].equals(list.get(j).getName())){
                                lv.setItemChecked(j, true);
                                break;
                            }
                        }
                    }
                }
//                        dialog.dismiss();
            }
        });
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                ItemListBean bean1 = adapter.getItem(i);
//                callback.run(bean1, dialog);
            }
        });
    }



    public static void showProductDialog(Context context, String title, String url, String name, ActionCallback callback
    ) {
        String token = (String) SPUtils.get(context, "token", "");
        String mCompanyId = (String) SPUtils.get(context, "cpy_id", "");

        ItemListAdapter adapter = new ItemListAdapter(context);
        List<ItemListBean> list = new ArrayList<>();
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        lv.setAdapter(adapter);
        builder                //对话框的标题
                .setTitle("选择" + title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //获取用户输入的“用户名”，“密码”
                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
        BaseNetUtil.baseProduct(context, title, url, name, list, token, mCompanyId, adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean bean1 = adapter.getItem(i);
                callback.run(bean1, dialog);
            }
        });
    }

    public static void showDialog(Context context, String title, String url, String name, String id, ActionCallback callback
    ) {
        String token = (String) SPUtils.get(context, "token", "");
        String mCompanyId = (String) SPUtils.get(context, "cpy_id", "");

        ItemListAdapter adapter = new ItemListAdapter(context);
        List<ItemListBean> list = new ArrayList<>();
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        lv.setAdapter(adapter);
        builder                //对话框的标题
                .setTitle("选择" + title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //获取用户输入的“用户名”，“密码”
                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
        BaseNetUtil.baseList(context, title, url, name, id, list, token, mCompanyId, adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean bean1 = adapter.getItem(i);
                callback.run(bean1, dialog);
            }
        });
    }

    //    根据传入的企业ID选择
    public static void showDialog(Context context, String title, String url, String name, String id, String companyId, ActionCallback callback
    ) {
        String token = (String) SPUtils.get(context, "token", "");
        String mCompanyId = companyId;

        ItemListAdapter adapter = new ItemListAdapter(context);
        List<ItemListBean> list = new ArrayList<>();
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        lv.setAdapter(adapter);
        builder                //对话框的标题
                .setTitle("选择" + title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //获取用户输入的“用户名”，“密码”
                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
        BaseNetUtil.baseList(context, title, url, name, id, list, token, mCompanyId, adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean bean1 = adapter.getItem(i);
                callback.run(bean1, dialog);
            }
        });
    }

    //    固定列表
    public static void showDialog(Context context, String title, String[] str, String name, ActionCallback callback
    ) {
        String token = (String) SPUtils.get(context, "token", "");
        String mCompanyId = (String) SPUtils.get(context, "cpy_id", "");

        ItemListAdapter adapter = new ItemListAdapter(context);
        List<ItemListBean> list = new ArrayList<>();
        for (int i = 0; i < str.length; i++) {
            list.add(new ItemListBean(str[i], i + ""));
        }
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        lv.setAdapter(adapter);
        adapter.refreshData(list);
        builder                //对话框的标题
                .setTitle("选择" + title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //获取用户输入的“用户名”，“密码”
                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean bean1 = adapter.getItem(i);
                callback.run(bean1, dialog);
            }
        });
    }

    public static void showDialog(Context context, String title, List<ItemListBean> list, ActionCallback callback
    ) {
        String token = (String) SPUtils.get(context, "token", "");
        String mCompanyId = (String) SPUtils.get(context, "cpy_id", "");

        ItemListAdapter adapter = new ItemListAdapter(context);
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_list, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        TextView tv_noData = (TextView) textEntryView.findViewById(R.id.tv_nodata);
        lv.setAdapter(adapter);
        builder                //对话框的标题
                .setTitle("选择" + title)
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //获取用户输入的“用户名”，“密码”
                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();
        adapter.refreshData(list);
        if (list.size()==0){
            tv_noData.setVisibility(View.VISIBLE);
        }
        else {
            tv_noData.setVisibility(View.GONE);

        }
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean bean1 = adapter.getItem(i);
                callback.run(bean1, dialog);
            }
        });
    }


    public static List getList(String[] items) {
        List<ItemListBean> listItem = new ArrayList<>();
        for (int i = 0; i < items.length; i++) {
            ItemListBean bean = new ItemListBean(items[i], i + "");
            listItem.add(bean);
        }
        return listItem;
    }
    public static List getList(String[] items,int index) {
        List<ItemListBean> listItem = new ArrayList<>();
        for (int i = 0; i < items.length; i++) {
            int num=i+index;
            ItemListBean bean = new ItemListBean(items[i], num + "");
            listItem.add(bean);
        }
        return listItem;
    }

    public static void mutiCheckDialog(Activity context, String title, String url, final String ids, ActionCallback callback) {

        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化

        new android.support.v7.app.AlertDialog.Builder(context)
                //对话框的标题
                .setTitle("确认审核选中的" + title + "吗？")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        check(ids, url, callback);
                    }

                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();
    }

    public static Dialog selectNewDialog(Context context, List<DialogBean> beanList, ActionCallback callback) {
        Animation slide_left_to_left, slide_right_to_left, slide_left_to_right, slide_left_to_left_in;
        RelativeLayout rlIten1, rlItem2, rlItem3, rlBase;
        LinearLayout llItem, ll;
        Button btnSearch;
        MyListView lvItem;
        final List<ItemListBean> listItem = new ArrayList<ItemListBean>();
        ItemListAdapter adapterItem;
        ImageView imageCloseOne, imageCloseTwo, iv_back, iv_del1, iv_del2, iv_del3;
        TextView tv_content1, tv_content2, tv_content3, tv_none;
        Dialog dialog;
        EditText et_content1, et_content2;
        adapterItem = new ItemListAdapter(context);
        dialog = new Dialog(context, R.style.BottomDialog);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置Content前设定
        dialog.setContentView(R.layout.dialog_select_normal);
        dialog.setCanceledOnTouchOutside(true); // 外部点击取消
        // 设置宽度为屏宽, 靠近屏幕底部。
        final Window window = dialog.getWindow();
        window.setWindowAnimations(R.style.AnimBottom);
        final WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.BOTTOM; // 紧贴底部
        lp.width = WindowManager.LayoutParams.MATCH_PARENT; // 宽度持平
        DisplayMetrics dm2 = context.getResources().getDisplayMetrics();
        lp.height = (int) (dm2.heightPixels * 0.6);
        window.setAttributes(lp);
        slide_left_to_left = AnimationUtils.loadAnimation(context, R.anim.slide_left_to_left);
        slide_right_to_left = AnimationUtils.loadAnimation(context, R.anim.slide_right_to_left);
        slide_left_to_right = AnimationUtils.loadAnimation(context, R.anim.slide_left_to_right);
        slide_left_to_left_in = AnimationUtils.loadAnimation(context, R.anim.slide_left_to_left_in);


        rlBase = (RelativeLayout) dialog.findViewById(R.id.re_pay_detail);//付款详情
        llItem = (LinearLayout) dialog.findViewById(R.id.lin_pay_way);//付款方式
        ll = (LinearLayout) dialog.findViewById(R.id.ll);//付款方式

        lvItem = (MyListView) dialog.findViewById(R.id.lv_bank);//付款方式（银行卡列表）
        lvItem.setAdapter(adapterItem);

        btnSearch = (Button) dialog.findViewById(R.id.btn_search);
        imageCloseOne = (ImageView) dialog.findViewById(R.id.close_one);
        imageCloseTwo = (ImageView) dialog.findViewById(R.id.close_two);


        iv_back = (ImageView) dialog.findViewById(R.id.iv_back);


        for (int i = 0; i < beanList.size(); i++) {
            int position = i;
            int h = dip2px(context, 1);

            RelativeLayout relativeLayout = new RelativeLayout(new ContextThemeWrapper(context, R.style.rl_et_parent_code));
            RelativeLayout.LayoutParams rlParams0 =
                    new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.WRAP_CONTENT,
                            RelativeLayout.LayoutParams.WRAP_CONTENT);
            RelativeLayout.LayoutParams rlParams =
                    new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.WRAP_CONTENT,
                            RelativeLayout.LayoutParams.WRAP_CONTENT);
            RelativeLayout.LayoutParams rlParams2 =
                    new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.WRAP_CONTENT,
                            RelativeLayout.LayoutParams.WRAP_CONTENT);
            DialogBean bean = beanList.get(i);
            TextView textView = new TextView(new ContextThemeWrapper(context, R.style.tv_select_title_left_code));
            textView.setText(bean.getName());
            textView.setId(R.id.tv_code_title);
            rlParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            rlParams.addRule(RelativeLayout.CENTER_VERTICAL);
            relativeLayout.addView(textView, rlParams);

            switch (bean.getType()) {
//                编辑框
                case 0:
                    ClearEditText editText = new ClearEditText(new ContextThemeWrapper(context, R.style.et_select_right_code));
                    editText.setId(R.id.tv_code_content);
                    editText.setHint("请输入");
                    editText.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                        }

                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                        }

                        @Override
                        public void afterTextChanged(Editable s) {
                            bean.setResult(editText.getText().toString());
                        }
                    });
                    editText.setBackground(null);
                    if (StringUtils.isNotEmpty(bean.getResult())){
                        editText.setText(bean.getResult());
                    }
                    rlParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                    rlParams2.addRule(RelativeLayout.CENTER_VERTICAL);
                    relativeLayout.addView(editText, rlParams2);
                    ll.addView(relativeLayout, rlParams0);


                    break;
//                    选择框
                case 1:

                    ImageView imageView = new ImageView(new ContextThemeWrapper(context, R.style.iv_select_del_code));
                    imageView.setId(R.id.tv_code_img);
                    imageView.setImageResource(R.mipmap.right);
                    imageView.setPadding(5 * h, 5 * h, 5 * h, 5 * h);


                    rlParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                    rlParams2.addRule(RelativeLayout.CENTER_VERTICAL);

                    relativeLayout.addView(imageView, rlParams2);

                    TextView tv_content = new TextView((new ContextThemeWrapper(context, R.style.tv_select_right_code)));
                    RelativeLayout.LayoutParams rlParams3 =
                            new RelativeLayout.LayoutParams(
                                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                                    RelativeLayout.LayoutParams.WRAP_CONTENT);
                    rlParams3.addRule(RelativeLayout.LEFT_OF, imageView.getId());
                    rlParams3.addRule(RelativeLayout.CENTER_VERTICAL);

                    relativeLayout.addView(tv_content, rlParams3);
                    relativeLayout.setFocusableInTouchMode(false);
                    if (StringUtils.isNotEmpty(bean.getContent())){
                        tv_content.setText(bean.getContent());
                        imageView.setImageResource(R.mipmap.b_shut);

                    }
                    relativeLayout.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            adapterItem.refreshData(bean.getListItem());
                            lvItem.setTag(R.id.a, position);
                            lvItem.setTag(R.id.b, tv_content);
                            lvItem.setTag(R.id.c, imageView);

                            rlBase.startAnimation(slide_left_to_left);
                            rlBase.setVisibility(View.GONE);
                            llItem.startAnimation(slide_right_to_left);
                            llItem.setVisibility(View.VISIBLE);
                        }
                    });
                                     imageView.setOnClickListener(v -> {
                        bean.setResult(null);
                        tv_content.setText("请选择");
                        imageView.setImageResource(R.mipmap.right);
                    });

                    ll.addView(relativeLayout, rlParams0);

                    break;


                case 2:

                     imageView = new ImageView(new ContextThemeWrapper(context, R.style.iv_select_del_code));
                    imageView.setId(R.id.tv_code_img);
                    imageView.setImageResource(R.mipmap.right);
                    imageView.setPadding(5 * h, 5 * h, 5 * h, 5 * h);


                    rlParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                    rlParams2.addRule(RelativeLayout.CENTER_VERTICAL);

                    relativeLayout.addView(imageView, rlParams2);

                     tv_content = new TextView((new ContextThemeWrapper(context, R.style.tv_select_right_code)));
                   rlParams3 =
                            new RelativeLayout.LayoutParams(
                                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                                    RelativeLayout.LayoutParams.WRAP_CONTENT);
                    rlParams3.addRule(RelativeLayout.LEFT_OF, imageView.getId());
                    rlParams3.addRule(RelativeLayout.CENTER_VERTICAL);

                    relativeLayout.addView(tv_content, rlParams3);
                    relativeLayout.setFocusableInTouchMode(false);
                    relativeLayout.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                        ViewUtil.getDate(context,tv_content,new DefaultAcitonCallback(){
                            @Override
                            public void run() {
                                super.run();
                                bean.setResult(tv_content.getText().toString());
                            }
                        });
                        }
                    });
                    if (StringUtils.isNotEmpty(bean.getContent())){
                        tv_content.setText(bean.getContent());
                        imageView.setImageResource(R.mipmap.b_shut);
                    }
                    imageView.setOnClickListener(v -> {
                        bean.setResult(null);
                        tv_content.setText("请选择");
                        imageView.setImageResource(R.mipmap.right);
                    });
                    ll.addView(relativeLayout, rlParams0);
                    break;

            }
            View line = new View(context);
            line.setBackgroundColor(Color.parseColor("#F1F1F3"));
            RelativeLayout.LayoutParams vParams =
                    new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.MATCH_PARENT,
                            h);

            ll.addView(line, vParams);
        }


        tv_none = (TextView) dialog.findViewById(R.id.tv_none);

        et_content1 = (EditText) dialog.findViewById(R.id.et_content1);
        et_content2 = (EditText) dialog.findViewById(R.id.et_content2);
        lvItem.setTag(1);


        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                KeybordS.hideKeyboard(view);

                switch (view.getId()) {

                    case R.id.iv_back:
                        rlBase.startAnimation(slide_left_to_left_in);
                        rlBase.setVisibility(View.VISIBLE);
                        llItem.startAnimation(slide_left_to_right);
                        llItem.setVisibility(View.GONE);

                        break;
                    case R.id.btn_search://确认付款

//                    search();
                        callback.run();
                        break;
                    case R.id.close_one:
                        dialog.dismiss();
                        break;
                    case R.id.close_two:
                        dialog.dismiss();
                        break;

                    default:
                        break;
                }
            }
        };


        btnSearch.setOnClickListener(listener);
        imageCloseOne.setOnClickListener(listener);
        imageCloseTwo.setOnClickListener(listener);
        iv_back.setOnClickListener(listener);

        lvItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean bean = adapterItem.getItem(i);
                int position = (int) lvItem.getTag(R.id.a);
                TextView tv_content = (TextView) lvItem.getTag(R.id.b);
                ImageView imageView = (ImageView) lvItem.getTag(R.id.c);
                imageView.setImageResource(R.mipmap.b_shut);
                beanList.get(position).setResult(bean.getID());
                beanList.get(position).setContent(bean.getName());
                tv_content.setText(bean.getName());
                rlBase.startAnimation(slide_left_to_left_in);
                rlBase.setVisibility(View.VISIBLE);
                llItem.startAnimation(slide_left_to_right);
                llItem.setVisibility(View.GONE);
                if ( beanList.get(position).getActionCallback()!=null){
                    beanList.get(position).getActionCallback().run(bean,null);
                }
            }


        });

        return dialog;

    }


    public static void mutiCheckDialog(Activity context, String title, String action, String url, final String ids, ActionCallback callback) {

        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化

        new android.support.v7.app.AlertDialog.Builder(context)
                //对话框的标题
                .setTitle("确认" + action + "选中的" + title + "吗？")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        check(ids, url, callback);
                    }

                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();
    }
//    需要传字段名称
    public static void mutiCheckDialog(Activity context, String title, String action, String url, String name,final String ids, ActionCallback callback) {

        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化

        new android.support.v7.app.AlertDialog.Builder(context)
                //对话框的标题
                .setTitle("确认" + action + "选中的" + title + "吗？")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        check(name,ids, url, callback);
                    }

                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();
    }
    private static void check(String ids, String url, ActionCallback callback) {
        MyApplication myApplication;
        myApplication = MyApplication.getInstance();
        String token = (String) SPUtils.get(myApplication, "token", "");
        Map<String, String> map = new HashMap<String, String>();

        map.put("ids", ids);

        String str = JsonUtils.obj2JsonString(map);
        OkHttpUtils
                .post(url + ids)
                .headers("token", token)
                .postJson(str)
                .execute(new StringCallback() {

                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "操作: " + result);
                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,myApplication);


                        if (code == 0) {
                            ToastUtil.makeText(myApplication, jsonObj.getString("msg"));
                            callback.run();

                        } else {
                            ToastUtil.makeText(myApplication, jsonObj.getString("msg"));
                        }

                    }
                });
    }
//get
    private static void check(String name,String ids, String url, ActionCallback callback) {
        MyApplication myApplication;
        myApplication = MyApplication.getInstance();
        String token = (String) SPUtils.get(myApplication, "token", "");
        Map<String, String> map = new HashMap<String, String>();

        map.put(name, ids);

        String str = JsonUtils.obj2JsonString(map);
        OkHttpUtils
                .get(url)
                .headers("token", token)
                .params(name,ids)
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "操作: " + result);
                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,myApplication);


                        if (code == 0) {
                            ToastUtil.makeText(myApplication, jsonObj.getString("msg"));
                            callback.run();

                        } else {
                            ToastUtil.makeText(myApplication, jsonObj.getString("msg"));
                        }

                    }
                });
    }
//添加已经选择产线的补集

    public static void showAddBeltDialog(Context context, CommonAdapter<DeviceHouseDayPlanMappingEntity> adapter, List<DeviceHouseDayPlanMappingEntity> list, List<DeviceHouseDayPlanMappingEntity> listRemove

    ) {
        String token = (String) SPUtils.get(context, "token", "");
        final android.support.v7.app.AlertDialog dialog;
        final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
        LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(R.layout.dialog_dayplan_belt_add, null);
        List<ItemListBean> arrayList = new ArrayList<>();
        DeviceHouseDayPlanMappingEntity bean=new DeviceHouseDayPlanMappingEntity();
for (DeviceHouseDayPlanMappingEntity entity:listRemove){
    arrayList.add(new ItemListBean(entity.getBeltlineName(),entity.getBeltlineId()+""));
}


        EditText et_plan = (EditText) textEntryView.findViewById(R.id.et_belt_plan);
        TextView tv_beltline = (TextView) textEntryView.findViewById(R.id.tv_beltline);
        tv_beltline.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtils.showDialog(context, "产线名称", arrayList, new DefaultAcitonCallback() {
                    @Override
                    public void run(ItemListBean bean1, Dialog dialog) {
                        bean.setBeltlineId(Long.valueOf(bean1.getID()));
                        bean.setBeltlineName(bean1.getName());
                        bean.setPlanOutput(0);
                        tv_beltline.setText(bean1.getName());
                        dialog.dismiss();
                    }
                });
            }
        });

        builder                //对话框的标题
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        if (StringUtils.isEmpty(tv_beltline.getText().toString())){
                            ToastUtil.makeText(context,"请选择产线");
                            return;
                        }
                        if (StringUtils.isEmpty(et_plan.getText().toString())){
                            ToastUtil.makeText(context,"产线计划产量不得为空");
                            return;
                        }
                        list.add(bean);
                        try {
                            bean.setPlanOutput(Integer.valueOf(et_plan.getText().toString()));
                        } catch (NumberFormatException e) {
                            e.printStackTrace();
                            bean.setPlanOutput(0);

                        }
                        listRemove.clear();
                        adapter.notifyDataSetChanged();

                    }
                })
                //对话框的“退出”单击事件
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                .create();
        dialog = builder.show();

    }
//

}
